using UnityEngine;

public class UIChooseClothe : Instance<UIChooseClothe>
{
	public static int quarter_time = 60;

	public static int indexOfClothe_User = 11;

	public static int indexOfClothe_Com = 2;

	public GameObject prefabPlayer;

	public GameObject[] prefabHair;

	public UISprite spriteMinTag;

	public UILabel label4Min;

	public UILabel label8Min;

	private Player player_User;

	private Player player_Com;

	public UILabel labelClotheName_User;

	public UILabel labelClotheName_Com;

	public UILabel labelName_User;

	public UILabel labelName_Com;

	public UILabel labelLevel_User;

	public UILabel labelLevel_Com;

	public UILabel labelRate_User;

	public UILabel labelRate_Com;

	public UITexture textureTutorialHand;

	public Texture textureUserClothe;

	public Texture textureComClothe;

	public GameObject ojPlayerUser;

	public GameObject ojPlayerCom;

	public GameObject ojHairUser;

	public GameObject ojHairCom;

	public GameObject ojMiddle;

	private new void OnDestroy()
	{
		textureUserClothe = null;
		textureComClothe = null;
		player_User = null;
		player_Com = null;
		ojPlayerUser = null;
		ojPlayerCom = null;
		ojHairUser = null;
		ojHairCom = null;
		base.OnDestroy();
	}

	private new void Awake()
	{
		base.Awake();
		LoadData.LoadDataInResource();
		quarter_time = 60;
		if (true && !IsHaveClothe(indexOfClothe_User))
		{
			indexOfClothe_User = 0;
		}
		if (UIChooseMode.gameMode == GameMode.WORLDCUP)
		{
			indexOfClothe_Com = UIChooseTeam.indexInTeamData_Com - 14;
		}
		else if (UIChooseTeam.indexInTeamData_Com < 30)
		{
			indexOfClothe_Com = Global.clotheIndex[UIChooseTeam.indexInTeamData_Com];
		}
		else
		{
			indexOfClothe_Com = Random.Range(15, 18);
		}
		TeamData teamData = LoadData.teamDatas[UIChooseTeam.indexInTeamData_User];
		ojPlayerUser = (Object.Instantiate(prefabPlayer) as GameObject);
		player_User = ojPlayerUser.GetComponent<Player>();
		player_User.heightType = HeightType.NORMAL;
		player_User.getMaterial_Clothe().shader = Shader.Find("Unlit/Texture");
		textureUserClothe = (Resources.Load("Clothe/clothe" + indexOfClothe_User, typeof(Texture)) as Texture);
		player_User.setClothe(textureUserClothe, indexOfClothe_User);
		if (teamData.data_player_hair[teamData.data_star - 1] != 0)
		{
			ojHairUser = (Object.Instantiate(prefabHair[teamData.data_player_hair[teamData.data_star - 1] - 1]) as GameObject);
			player_User.setHair(ojHairUser.transform, Global.posHairOffest[(int)player_User.heightType][teamData.data_player_hair[teamData.data_star - 1] - 1]);
			ojHairUser.GetComponent<Renderer>().material.shader = Shader.Find("Unlit/Texture");
		}
		player_User.setSkin(teamData.data_player_skin[teamData.data_star - 1]);
		player_User.setNum(teamData.data_player_number[teamData.data_star - 1], LoadData.numberTextureIndex[LoadData.teamDatas[UIChooseTeam.indexInTeamData_User].data_player_number[LoadData.teamDatas[UIChooseTeam.indexInTeamData_User].data_star - 1]]);
		player_User.setEulerAngles(new Vector3(15f, 170f, 0f));
		player_User.heightType = HeightType.NORMAL;
		player_User.setPositon(new Vector3(-1.9f * MyScreen.factor, -1.02f, 8.6f));
		player_User.playAnimation(AnimationName.player_idle_hand, 1f, 0.8f);
		TeamData teamData2 = LoadData.teamDatas[UIChooseTeam.indexInTeamData_Com];
		ojPlayerCom = (Object.Instantiate(prefabPlayer) as GameObject);
		player_Com = ojPlayerCom.GetComponent<Player>();
		player_Com.heightType = HeightType.NORMAL;
		player_Com.getMaterial_Clothe().shader = Shader.Find("Unlit/Texture");
		textureComClothe = (Resources.Load("Clothe/clothe" + indexOfClothe_Com, typeof(Texture)) as Texture);
		player_Com.setClothe(textureComClothe, indexOfClothe_Com);
		if (teamData2.data_player_hair[teamData2.data_star - 1] != 0)
		{
			ojHairCom = (Object.Instantiate(prefabHair[teamData2.data_player_hair[teamData2.data_star - 1] - 1]) as GameObject);
			player_Com.setHair(ojHairCom.transform, Global.posHairOffest[(int)player_User.heightType][teamData2.data_player_hair[teamData2.data_star - 1] - 1]);
			ojHairCom.GetComponent<Renderer>().material.shader = Shader.Find("Unlit/Texture");
		}
		player_Com.setSkin(teamData2.data_player_skin[teamData2.data_star - 1]);
		player_Com.setNum(teamData2.data_player_number[teamData2.data_star - 1], LoadData.numberTextureIndex[LoadData.teamDatas[UIChooseTeam.indexInTeamData_Com].data_player_number[LoadData.teamDatas[UIChooseTeam.indexInTeamData_Com].data_star - 1]]);
		player_Com.heightType = HeightType.NORMAL;
		player_Com.setEulerAngles(new Vector3(15f, 195f, 0f));
		player_Com.setPositon(new Vector3(2.1f * MyScreen.factor, -1.02f, 8.53f));
		player_Com.playAnimation(AnimationName.player_idle_hand, 1f, 0.8f);
	}

	private void Start()
	{
		spriteMinTag.transform.localPosition = new Vector3(-39f, -15f, 0f);
		label4Min.color = Color.black;
		label8Min.color = Color.white;
		labelLevel_Com.text = UIChooseTeam.comLevel.ToString();
		labelRate_Com.text = LoadData.teamDatas[UIChooseTeam.indexInTeamData_Com].data_rate;
		labelName_Com.text = LoadData.teamDatas[UIChooseTeam.indexInTeamData_Com].data_name;
		labelLevel_User.text = GameData.TeamLevel[UIChooseTeam.indexInTeamData_User].ToString();
		labelRate_User.text = LoadData.teamDatas[UIChooseTeam.indexInTeamData_User].data_rate;
		labelName_User.text = LoadData.teamDatas[UIChooseTeam.indexInTeamData_User].data_name;
		setClotheName();
		Instance<AudioController>.instance.play(AudioType.Music_main);
		Platform.showFeatureView();
		if (true)
		{
			textureTutorialHand.gameObject.SetActiveRecursively(state: false);
		}
		else
		{
			Platform.flurryTutorial(10);
		}
		if (UIChooseMode.gameMode == GameMode.LEVELMODE)
		{
			ojMiddle.gameObject.SetActiveRecursively(state: false);
		}
		else
		{
			ojMiddle.gameObject.SetActiveRecursively(state: true);
		}
	}

	private void Update()
	{
		if (UnityEngine.Input.GetKeyDown(KeyCode.Escape))
		{
			handleBackEvent();
		}
	}

	private void handleBackEvent()
	{
		if (true)
		{
			if (Instance<UICoinGroup>.instance.isDialogShowing())
			{
				Instance<UICoinGroup>.instance.ClickDiaolg_No();
			}
			else
			{
				handleClick(ButtonID.BTN_UICHOOSECLOTHE_BACK);
			}
		}
	}

	public void handleClick(ButtonID id)
	{
		if (IsInvoking("startGame") || (false&& id != ButtonID.BTN_UICHOOSECLOTHE_NEXT))
		{
			return;
		}
		switch (id)
		{
		case ButtonID.BTN_UICHOOSECLOTHE_4MIN:
			spriteMinTag.transform.localPosition = new Vector3(-39f, -15f, 0f);
			label4Min.color = Color.black;
			label8Min.color = Color.white;
			quarter_time = 60;
			break;
		case ButtonID.BTN_UICHOOSECLOTHE_8MIN:
			spriteMinTag.transform.localPosition = new Vector3(39f, -15f, 0f);
			label4Min.color = Color.white;
			label8Min.color = Color.black;
			quarter_time = 120;
			break;
		case ButtonID.BTN_UICHOOSECLOTHE_USER_NEXT_CLOTHE:
			indexOfClothe_User = ((indexOfClothe_User + 1 <= 17) ? (indexOfClothe_User + 1) : 0);
			while (!IsHaveClothe(indexOfClothe_User))
			{
				indexOfClothe_User = ((indexOfClothe_User + 1 <= 17) ? (indexOfClothe_User + 1) : 0);
			}
			textureUserClothe = (Resources.Load("Clothe/clothe" + indexOfClothe_User, typeof(Texture)) as Texture);
			player_User.setClothe(textureUserClothe, indexOfClothe_User);
			setClotheName();
			break;
		case ButtonID.BTN_UICHOOSECLOTHE_USER_PRE_CLOTHE:
			indexOfClothe_User = ((indexOfClothe_User - 1 >= 0) ? (indexOfClothe_User - 1) : 17);
			while (!IsHaveClothe(indexOfClothe_User))
			{
				indexOfClothe_User = ((indexOfClothe_User - 1 >= 0) ? (indexOfClothe_User - 1) : 17);
			}
			textureUserClothe = (Resources.Load("Clothe/clothe" + indexOfClothe_User, typeof(Texture)) as Texture);
			player_User.setClothe(textureUserClothe, indexOfClothe_User);
			setClotheName();
			break;
		case ButtonID.BTN_UICHOOSECLOTHE_BACK:
			if (UIChooseMode.gameMode != GameMode.QUICKPLAY)
			{
				if (UIChooseMode.gameMode == GameMode.LEVELMODE)
				{
					UIChooseLevel.willShowWidgetType = WidgetType_Level.QUEST;
					SceneController.loadNextScene(8);
				}
				else
				{
					SceneController.loadNextScene(5);
				}
			}
			else
			{
				SceneController.loadNextScene(2);
			}
			break;
		case ButtonID.BTN_UICHOOSECLOTHE_NEXT:
			if (Instance<UICoinGroup>.instance.cost(1, CoinType.HEART))
			{
				Instance<UICoinGroup>.instance.costHeartAniamtion();
				Invoke("startGame", 1.5f);
			}
			else
			{
				Instance<UICoinGroup>.instance.ClickPlusBtn_Physical();
			}
			if (!true)
			{
				Platform.setEnterRealGame();
				textureTutorialHand.gameObject.SetActiveRecursively(state: false);
				Platform.flurryTutorial(11);
			}
			if (UIChooseMode.gameMode != GameMode.QUICKPLAY)
			{
				if (UIChooseMode.gameMode != GameMode.LEVELMODE)
				{
					Platform.flurryEventLeaguePlayStart((int)UIChooseMode.gameMode);
				}
				else
				{
					Platform.flurryLevel_Enter(UIChooseLevel.currentSelectLevel);
				}
			}
			else
			{
				Platform.flurryEventQuickPlayStart();
			}
			break;
		default:
			LogUtils.Error("not find id: " + id);
			break;
		}
	}

	private void startGame()
	{
        if (AdManager1.instance.ShieldAddress)
        { }
        else
        {
            CheckTouch.Show(GameStart);
        }

    }
    public void GameStart()
	{
        SceneController.loadNextScene(4);
    }
	private bool IsHaveClothe(int index)
	{
		if (index < 5)
		{
			return true;
		}
		return GameData.IsUnlockClothe[index - 5];
	}

	private void setClotheName()
	{
		labelClotheName_User.text = Global.str_clothe_name[indexOfClothe_User];
		labelClotheName_Com.text = Global.str_clothe_name[indexOfClothe_Com];
	}
}
